﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Origin2.Core;
using Origin2.Framework.Managers.Input;

namespace Origin2Test.Controls
{
    public class KeyboardMovementControl : Control
    {
        public const float MovementSpeed = 128f;

        public KeyboardMovementControl(IControllable parent) : base(parent)
        {
            
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            var trans = ((ITransformable) Parent).Transform;

            if (KeyboardManager.CurrentKeyboardState.IsKeyDown(Keys.D))
                trans.TranslateX(MovementSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
            if (KeyboardManager.CurrentKeyboardState.IsKeyDown(Keys.A))
                trans.TranslateX(-MovementSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
            if (KeyboardManager.CurrentKeyboardState.IsKeyDown(Keys.W))
                trans.TranslateY(-MovementSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
            if (KeyboardManager.CurrentKeyboardState.IsKeyDown(Keys.S))
                trans.TranslateY(MovementSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
        }
    }
}
